package com.sftz.modules.admin.authority.user.form;

import java.util.ArrayList;
import java.util.List;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;

import com.sftz.framework.mvc.access.AccessConfig;
import com.sftz.framework.mvc.access.sign.MD5;
import com.sftz.framework.res.entities.SUserRoleMapEntity;
import com.sftz.framework.res.enums.UserStatusEnum;
import com.sftz.framework.res.enums.UserTypeEnum;
import com.uxuexi.core.common.util.Util;
import com.uxuexi.core.web.form.ModForm;

@Data
@EqualsAndHashCode(callSuper = false)
public class UserModForm extends ModForm {

	/**
	 * 登录名
	 */
	@NotEmpty
	private String username;

	/**
	 * 登录密码
	 */
	private String password;

	/**
	 * 用户状态:0-未激活，1-激活，2-冻结
	 * @see UserStatusEnum
	 */
	@Range(min = 0, max = 2)
	private Integer status;

	/**
	 * 用户类型:1-普通用户，2-系统用户
	 * @see UserTypeEnum
	 */
	@Range(min = 1, max = 2)
	private Integer userType;

	/**用户的角色*/
	private List<SUserRoleMapEntity> map = new ArrayList<SUserRoleMapEntity>();

	public void setPassword(String password) {
		if (!Util.isEmpty(password)) {
			this.password = MD5.sign(password, AccessConfig.password_secret, AccessConfig.INPUT_CHARSET);
		}
	}
}
